package cn.sz.hy.ui.widget.center;

import java.util.List;

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;

import cn.sz.hy.common.Globel;
import cn.sz.hy.logic.strategy.vo.SheetItem;
import cn.sz.hy.ui.frame.CenterPanel;
import cn.sz.hy.ui.widget.top.BasicPanel;

public class Row extends BasicPanel {

	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
	private Text text;
	private Combo combo_1;
	private Combo link;
	private SheetItem item;

	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public Row(Composite parent, int style) {
		super(parent, SWT.None);
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				toolkit.dispose();
			}
		});
		toolkit.adapt(this);
		toolkit.paintBordersFor(this);
		setLayout(new GridLayout(3, false));

		text = new Text(this, SWT.BORDER);
		text.addModifyListener(new ModifyListener(){
			public void modifyText(ModifyEvent arg0) {
				CenterPanel centerPanel = (CenterPanel) eBus.getComponent(Globel.CENTER_PANEL_ID);
				centerPanel.updateEditSelect();
			}
		});
		GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_text.widthHint = 184;
		text.setLayoutData(gd_text);
		toolkit.adapt(text, true, true);

		link = new Combo(this, SWT.NONE);
		link.add("None");
		link.add("Key Link");
		link.add("Insert Link");
		link.select(0);
		GridData gd_combo = new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
				1);
		gd_combo.widthHint = 105;
		link.setLayoutData(gd_combo);
		toolkit.adapt(link);
		toolkit.paintBordersFor(link);

		combo_1 = new Combo(this, SWT.NONE);
		GridData gd_combo_1 = new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1);
		gd_combo_1.widthHint = 126;
		combo_1.setLayoutData(gd_combo_1);
		toolkit.adapt(combo_1);
		toolkit.paintBordersFor(combo_1);

	}

	public Text getText() {
		return text;
	}

	public Combo getBackup() {
		return combo_1;
	}

	public SheetItem getItem() {
		return item;
	}

	public void setItem(SheetItem item) {
		this.item = item;
	}

	public Combo getLink() {
		return link;
	}

	public void loadBackList(List<String> items) {
		if(items == null){
			return;
		}
		combo_1.removeAll();
		for (String item : items) {
			combo_1.add(item);
		}
		combo_1.select(0);
	}
	
	public void restart(){
		text.setText("");
		combo_1.removeAll();
		setVisible(false);
	}

}
